package com.example.design.strategy.promotion;

import java.text.MessageFormat;

/**
 * @Description 购物-环境类
 * @ClassName Shopping
 * @Author Yumuhui
 * @Date 2020/5/15 0:36
 * @Version 1.0.0
 */
public class Shopping {
    private String goods;
    private double price;
    private Discount discount;

    public Shopping(String goods, double price) {
        this.goods = goods;
        this.price = price;
    }

    public Discount getDiscount() {
        return discount;
    }

    public void setDiscount(Discount discount) {
        this.discount = discount;
    }

    /**
     * 结算
     * @return
     */
    public double calculate() {
        double finalPrice = discount.discountMethod(this.price);
        String desc = discount.getDesc();
        System.out.println(MessageFormat.format("购买的物品：{0}，原始价格：{1}，{2}，最终价格为：{3}", goods, price, desc, finalPrice));
        return finalPrice;
    }
}
